using System;
using System.Data;
using System.Collections;
using APP.QUANLY.Entity;
using APP.QUANLY.Entity.ConditionForm;

namespace APP.QUANLY.DAL
{
    /// <summary>
    /// Summary description for MATHANG.
     /// </summary>
	public class MATHANGDao
    {
	    private string _SQLSelectByKey;
	    private string _SQLUpdate;
	    private string _SQLInsert;
	    private string _SQLDelete;
	    private string _SQLSelectAll;

        #region Properties

        public IDbConnection _dbConnection;

        public IDbConnection DbConnection
        {
            get { return _dbConnection; }
            set { _dbConnection = value; }
        }

        #endregion
        
        #region Constructor

        public MATHANGDao()
        {
            _dbConnection = null;
		    InitSqlQuery();
        }

        public MATHANGDao(IDbConnection con)
        {
            _dbConnection = con;
            InitSqlQuery();
        }

        #endregion


        private void ToLowerQuery()
        {
            _SQLDelete = _SQLDelete.ToLower();
            _SQLUpdate = _SQLUpdate.ToLower();
            _SQLInsert = _SQLInsert.ToLower();
            _SQLSelectByKey = _SQLSelectByKey.ToLower();
        }

        private void ToUpperQuery()
        {
            _SQLDelete = _SQLDelete.ToUpper();
            _SQLUpdate = _SQLUpdate.ToUpper();
            _SQLInsert = _SQLInsert.ToUpper();
            _SQLSelectByKey = _SQLSelectByKey.ToUpper();
        }

        #region InitSqlQuery
        private void InitSqlQuery()
       {
            string query;

            query = @"SELECT MAMATHANG, MABARCODE, MACODE, TENMATHANG, HINHANH, MADONVISI, MADONVILE, SOLUONGQUYDOI, VAT, CHIETKHAU, XUATXU, GIANHAP, GIALE, GIAQUYDINH, GIACHIATHANG, GIAKHUYENMAI, NGUONGNHAP, NGUONGXUAT, ISKHUYENMAI, ISUSE, ISDELETE, ISTHEODOI, NGAYTAO, NGUOITAO, NGAYCAPNHAT, NGUOICAPNHAT, MALOAIMATHANG, GHICHU FROM MATHANG WHERE (MAMATHANG = @MAMATHANG)";
	        _SQLSelectByKey = query;

            query = @"UPDATE MATHANG SET MABARCODE = @MABARCODE, MACODE = @MACODE, TENMATHANG = @TENMATHANG, HINHANH = @HINHANH, MADONVISI = @MADONVISI, MADONVILE = @MADONVILE, SOLUONGQUYDOI = @SOLUONGQUYDOI, VAT = @VAT, CHIETKHAU = @CHIETKHAU, XUATXU = @XUATXU, GIANHAP = @GIANHAP, GIALE = @GIALE, GIAQUYDINH = @GIAQUYDINH, GIACHIATHANG = @GIACHIATHANG, GIAKHUYENMAI = @GIAKHUYENMAI, NGUONGNHAP = @NGUONGNHAP, NGUONGXUAT = @NGUONGXUAT, ISKHUYENMAI = @ISKHUYENMAI, ISUSE = @ISUSE, ISDELETE = @ISDELETE, ISTHEODOI = @ISTHEODOI, NGAYTAO = @NGAYTAO, NGUOITAO = @NGUOITAO, NGAYCAPNHAT = @NGAYCAPNHAT, NGUOICAPNHAT = @NGUOICAPNHAT, MALOAIMATHANG = @MALOAIMATHANG, GHICHU = @GHICHU WHERE (MAMATHANG = @MAMATHANG)";
	        _SQLUpdate = query;

            query = @"INSERT INTO MATHANG VALUES (@MABARCODE, @MACODE, @TENMATHANG, @HINHANH, @MADONVISI, @MADONVILE, @SOLUONGQUYDOI, @VAT, @CHIETKHAU, @XUATXU, @GIANHAP, @GIALE, @GIAQUYDINH, @GIACHIATHANG, @GIAKHUYENMAI, @NGUONGNHAP, @NGUONGXUAT, @ISKHUYENMAI, @ISUSE, @ISDELETE, @ISTHEODOI, @NGAYTAO, @NGUOITAO, @NGAYCAPNHAT, @NGUOICAPNHAT, @MALOAIMATHANG, @GHICHU)";
	        _SQLInsert = query;

            query = @"DELETE FROM MATHANG WHERE (MAMATHANG = @MAMATHANG)";
	        _SQLDelete = query;

            query = @"SELECT MAMATHANG, MABARCODE, MACODE, TENMATHANG, HINHANH, MADONVISI, MADONVILE, SOLUONGQUYDOI, VAT, CHIETKHAU, XUATXU, GIANHAP, GIALE, GIAQUYDINH, GIACHIATHANG, GIAKHUYENMAI, NGUONGNHAP, NGUONGXUAT, ISKHUYENMAI, ISUSE, ISDELETE, ISTHEODOI, NGAYTAO, NGUOITAO, NGAYCAPNHAT, NGUOICAPNHAT, MALOAIMATHANG, GHICHU FROM MATHANG";
	        _SQLSelectAll = query;
        }
        #endregion
        public void LoadByCommandText(string commandtext, IDbTransaction trans)
        {
            if (_dbConnection == null)
            {
                throw new Exception("Connection has not been set.");
            }

            IDbCommand command;

            try
            {
                if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); }

                command = _dbConnection.CreateCommand();
                command.CommandText = commandtext;

				if (trans != null) { command.Transaction = trans; }
                if (command.ExecuteNonQuery() == 0) { throw new Exception("Zero rows were affected."); }
            }
            catch (Exception ex) { throw ex; }
        }

        #region Save & Delete
        private void Save(MATHANG obj, IDbTransaction trans, bool isExisting)
        {
            if (_dbConnection == null) { throw new Exception("Connection has not been set."); }

            IDbCommand command;

            try
            {
                if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); }
                command = _dbConnection.CreateCommand();

                if (!isExisting) { command.CommandText = _SQLInsert + ";"; }
                else { command.CommandText = _SQLUpdate + ";"; }

                         DalTools.addDbDataParameter(command, "MAMATHANG", obj.MAMATHANG, DbType.Int32);
                         DalTools.addDbDataParameter(command, "MABARCODE", obj.MABARCODE, DbType.String);
         DalTools.addDbDataParameter(command, "MACODE", obj.MACODE, DbType.String);
         DalTools.addDbDataParameter(command, "TENMATHANG", obj.TENMATHANG, DbType.String);
         DalTools.addDbDataParameter(command, "HINHANH", obj.HINHANH, DbType.Binary);
         DalTools.addDbDataParameter(command, "MADONVISI", obj.MADONVISI, DbType.Int32);
         DalTools.addDbDataParameter(command, "MADONVILE", obj.MADONVILE, DbType.Int32);
         DalTools.addDbDataParameter(command, "SOLUONGQUYDOI", obj.SOLUONGQUYDOI, DbType.Int32);
         DalTools.addDbDataParameter(command, "VAT", obj.VAT, DbType.Int32);
         DalTools.addDbDataParameter(command, "CHIETKHAU", obj.CHIETKHAU, DbType.Double);
         DalTools.addDbDataParameter(command, "XUATXU", obj.XUATXU, DbType.String);
         DalTools.addDbDataParameter(command, "GIANHAP", obj.GIANHAP, DbType.Decimal);
         DalTools.addDbDataParameter(command, "GIALE", obj.GIALE, DbType.Decimal);
         DalTools.addDbDataParameter(command, "GIAQUYDINH", obj.GIAQUYDINH, DbType.Decimal);
         DalTools.addDbDataParameter(command, "GIACHIATHANG", obj.GIACHIATHANG, DbType.Decimal);
         DalTools.addDbDataParameter(command, "GIAKHUYENMAI", obj.GIAKHUYENMAI, DbType.Decimal);
         DalTools.addDbDataParameter(command, "NGUONGNHAP", obj.NGUONGNHAP, DbType.Decimal);
         DalTools.addDbDataParameter(command, "NGUONGXUAT", obj.NGUONGXUAT, DbType.Decimal);
         DalTools.addDbDataParameter(command, "ISKHUYENMAI", obj.ISKHUYENMAI, DbType.Boolean);
         DalTools.addDbDataParameter(command, "ISUSE", obj.ISUSE, DbType.Boolean);
         DalTools.addDbDataParameter(command, "ISDELETE", obj.ISDELETE, DbType.Boolean);
         DalTools.addDbDataParameter(command, "ISTHEODOI", obj.ISTHEODOI, DbType.Boolean);
         DalTools.addDbDataParameter(command, "NGAYTAO", obj.NGAYTAO, DbType.DateTime);
         DalTools.addDbDataParameter(command, "NGUOITAO", obj.NGUOITAO, DbType.String);
         DalTools.addDbDataParameter(command, "NGAYCAPNHAT", obj.NGAYCAPNHAT, DbType.DateTime);
         DalTools.addDbDataParameter(command, "NGUOICAPNHAT", obj.NGUOICAPNHAT, DbType.String);
         DalTools.addDbDataParameter(command, "MALOAIMATHANG", obj.MALOAIMATHANG, DbType.Int32);
         DalTools.addDbDataParameter(command, "GHICHU", obj.GHICHU, DbType.String);

		        if (trans != null) { command.Transaction = trans; }
                if (command.ExecuteNonQuery() == 0) { throw new Exception("Zero rows were affected."); }
            }
            catch (Exception ex) { throw ex; }
        }

        public void Delete(MATHANG obj, IDbTransaction trans)
        {
            if (_dbConnection == null)
            {
                //throw new DalException("Connection has not been set.");
                throw new Exception("Connection has not been set.");
            }

            IDbCommand command;

            try
            {
                if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); }

                command = _dbConnection.CreateCommand();
                command.CommandText = _SQLDelete + ";";

                         DalTools.addDbDataParameter(command, "MAMATHANG", obj.MAMATHANG, DbType.Int32);

		        if (trans != null) { command.Transaction = trans; }
                if (command.ExecuteNonQuery() == 0) { throw new Exception("Zero rows were affected."); }
            }
            catch (Exception ex) { throw ex; }
        }

        public void Insert(MATHANG obj, IDbTransaction trans)
        {
            Save(obj, trans, false);
        }
        public void Update(MATHANG obj, IDbTransaction trans)
        {
            Save(obj, trans, true);
        }
        #endregion

        #region Command Execute & Read Properties
     
        private MATHANGList SelectListByCommand(IDbCommand command)
        {
            MATHANGList list = new MATHANGList();
            if (_dbConnection == null) { throw new Exception("Connection has not been set."); }
            try
            {	
				MATHANG obj;
                if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); }
                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read()) 
					{ 
						obj = new MATHANG();
						ReadProperties(obj, reader);
						list.Add(obj); 
					}
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }
		
        private MATHANGList SelectListByCommand(IDbCommand command, IDbTransaction trans)
        {
            MATHANGList list = new MATHANGList();
            if (_dbConnection == null) { throw new Exception("Connection has not been set."); }
            try
            {	
				MATHANG obj;
                if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); }
				command.Transaction = trans;
                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read()) 
					{ 
						obj = new MATHANG();
						ReadProperties(obj, reader);
						list.Add(obj); 
					}
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }

        private void DeleteListByCommand(IDbCommand command, IDbTransaction trans)
        {
            if (_dbConnection == null) { throw new Exception("Connection has not been set."); }
            try
            {
                if (_dbConnection.State != ConnectionState.Open) { _dbConnection.Open(); }
                if (trans != null) { command.Transaction = trans; }
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
	
        private void ReadProperties(MATHANG obj, IDataReader reader)
        {
            try
            {
                                if(!(reader["MAMATHANG"] is DBNull))
		{
			obj.MAMATHANG = (Int32)reader["MAMATHANG"];
		}
                if(!(reader["MABARCODE"] is DBNull))
		{
			obj.MABARCODE = (string)reader["MABARCODE"];
		}
                if(!(reader["MACODE"] is DBNull))
		{
			obj.MACODE = (string)reader["MACODE"];
		}
                if(!(reader["TENMATHANG"] is DBNull))
		{
			obj.TENMATHANG = (string)reader["TENMATHANG"];
		}
                if(!(reader["HINHANH"] is DBNull))
		{
			obj.HINHANH = (byte[])reader["HINHANH"];
		}
                if(!(reader["MADONVISI"] is DBNull))
		{
			obj.MADONVISI = (Int32)reader["MADONVISI"];
		}
                if(!(reader["MADONVILE"] is DBNull))
		{
			obj.MADONVILE = (Int32)reader["MADONVILE"];
		}
                if(!(reader["SOLUONGQUYDOI"] is DBNull))
		{
			obj.SOLUONGQUYDOI = (Int32)reader["SOLUONGQUYDOI"];
		}
                if(!(reader["VAT"] is DBNull))
		{
			obj.VAT = (Int32)reader["VAT"];
		}
                if(!(reader["CHIETKHAU"] is DBNull))
		{
			obj.CHIETKHAU = (double)reader["CHIETKHAU"];
		}
                if(!(reader["XUATXU"] is DBNull))
		{
			obj.XUATXU = (string)reader["XUATXU"];
		}
                if(!(reader["GIANHAP"] is DBNull))
		{
			obj.GIANHAP = (decimal)reader["GIANHAP"];
		}
                if(!(reader["GIALE"] is DBNull))
		{
			obj.GIALE = (decimal)reader["GIALE"];
		}
                if(!(reader["GIAQUYDINH"] is DBNull))
		{
			obj.GIAQUYDINH = (decimal)reader["GIAQUYDINH"];
		}
                if(!(reader["GIACHIATHANG"] is DBNull))
		{
			obj.GIACHIATHANG = (decimal)reader["GIACHIATHANG"];
		}
                if(!(reader["GIAKHUYENMAI"] is DBNull))
		{
			obj.GIAKHUYENMAI = (decimal)reader["GIAKHUYENMAI"];
		}
                if(!(reader["NGUONGNHAP"] is DBNull))
		{
			obj.NGUONGNHAP = (decimal)reader["NGUONGNHAP"];
		}
                if(!(reader["NGUONGXUAT"] is DBNull))
		{
			obj.NGUONGXUAT = (decimal)reader["NGUONGXUAT"];
		}
                if(!(reader["ISKHUYENMAI"] is DBNull))
		{
			obj.ISKHUYENMAI = (bool)reader["ISKHUYENMAI"];
		}
                if(!(reader["ISUSE"] is DBNull))
		{
			obj.ISUSE = (bool)reader["ISUSE"];
		}
                if(!(reader["ISDELETE"] is DBNull))
		{
			obj.ISDELETE = (bool)reader["ISDELETE"];
		}
                if(!(reader["ISTHEODOI"] is DBNull))
		{
			obj.ISTHEODOI = (bool)reader["ISTHEODOI"];
		}
                if(!(reader["NGAYTAO"] is DBNull))
		{
			obj.NGAYTAO = (DateTime)reader["NGAYTAO"];
		}
                if(!(reader["NGUOITAO"] is DBNull))
		{
			obj.NGUOITAO = (string)reader["NGUOITAO"];
		}
                if(!(reader["NGAYCAPNHAT"] is DBNull))
		{
			obj.NGAYCAPNHAT = (DateTime)reader["NGAYCAPNHAT"];
		}
                if(!(reader["NGUOICAPNHAT"] is DBNull))
		{
			obj.NGUOICAPNHAT = (string)reader["NGUOICAPNHAT"];
		}
                if(!(reader["MALOAIMATHANG"] is DBNull))
		{
			obj.MALOAIMATHANG = (Int32)reader["MALOAIMATHANG"];
		}
                if(!(reader["GHICHU"] is DBNull))
		{
			obj.GHICHU = (string)reader["GHICHU"];
		}
            }
            catch (Exception ex)
            {
                throw new DalException("Failed to read properties from DataReader.", ex);
            }
        }
        #endregion
      
        public MATHANG SelectByKey(Int32 MAMATHANG)
        {
            IDbCommand command  = _dbConnection.CreateCommand();
            command.CommandText = _SQLSelectByKey;
	                 DalTools.addDbDataParameter(command, "MAMATHANG", MAMATHANG, DbType.Int32);
      	    MATHANGList list =  SelectListByCommand(command);

            if (list.Count == 0) { throw new Exception("No data was returned"); }
            return list[0];
        }

        public MATHANG SelectByKey(Int32 MAMATHANG, IDbTransaction trans)
        {
            IDbCommand command  = _dbConnection.CreateCommand();
            command.CommandText = _SQLSelectByKey;
	                 DalTools.addDbDataParameter(command, "MAMATHANG", MAMATHANG, DbType.Int32);
      	    MATHANGList list =  SelectListByCommand(command, trans);
			
            if (list.Count == 0) { throw new Exception("No data was returned"); }
            return list[0];
        }
		
        public MATHANGList SelectAll()
        {
            IDbCommand command  = _dbConnection.CreateCommand();
            command.CommandText = _SQLSelectAll;
      	    MATHANGList list =  SelectListByCommand(command);
	        return list;
        }

         public MATHANGList SelectByCommand(string Command)
        {
            IDbCommand command  = _dbConnection.CreateCommand();
            command.CommandText = Command;
      	    MATHANGList list =  SelectListByCommand(command);
	        return list;
        }

        public MATHANGList SelectByCondition(MATHANGConditionForm condt)
        {
            IDbCommand command = _dbConnection.CreateCommand();
            command.CommandText = "SELECT * FROM MATHANG " + GetCondtionQuery(condt) + ";";
            FillParamToCommand(command, condt);
            MATHANGList list = SelectListByCommand(command);
            return list;
        }

        private void DeleteByCondition(MATHANGConditionForm condt, IDbTransaction trans)
        {
            IDbCommand command = _dbConnection.CreateCommand();
            command.CommandText = "DELETE FROM MATHANG " + GetCondtionQuery(condt) + ";";
            FillParamToCommand(command, condt);
            DeleteListByCommand(command, trans);
        }

        #region Make Condition Query & Fill Param from Condition to Command
        private string GetCondtionQuery(MATHANGConditionForm obj)
        {
            if (obj == null) { return ""; }
            string s = "";
            	if (obj.IsSetMAMATHANG)
	{
    	    s += " AND MAMATHANG = @MAMATHANG ";
	}
	if (obj.IsSetMABARCODE)
	{
    	    s += " AND MABARCODE = @MABARCODE ";
	}
	if (obj.IsSetMACODE)
	{
    	    s += " AND MACODE = @MACODE ";
	}
	if (obj.IsSetTENMATHANG)
	{
    	    s += " AND TENMATHANG = @TENMATHANG ";
	}
	if (obj.IsSetHINHANH)
	{
    	    s += " AND HINHANH = @HINHANH ";
	}
	if (obj.IsSetMADONVISI)
	{
    	    s += " AND MADONVISI = @MADONVISI ";
	}
	if (obj.IsSetMADONVILE)
	{
    	    s += " AND MADONVILE = @MADONVILE ";
	}
	if (obj.IsSetSOLUONGQUYDOI)
	{
    	    s += " AND SOLUONGQUYDOI = @SOLUONGQUYDOI ";
	}
	if (obj.IsSetVAT)
	{
    	    s += " AND VAT = @VAT ";
	}
	if (obj.IsSetCHIETKHAU)
	{
    	    s += " AND CHIETKHAU = @CHIETKHAU ";
	}
	if (obj.IsSetXUATXU)
	{
    	    s += " AND XUATXU = @XUATXU ";
	}
	if (obj.IsSetGIANHAP)
	{
    	    s += " AND GIANHAP = @GIANHAP ";
	}
	if (obj.IsSetGIALE)
	{
    	    s += " AND GIALE = @GIALE ";
	}
	if (obj.IsSetGIAQUYDINH)
	{
    	    s += " AND GIAQUYDINH = @GIAQUYDINH ";
	}
	if (obj.IsSetGIACHIATHANG)
	{
    	    s += " AND GIACHIATHANG = @GIACHIATHANG ";
	}
	if (obj.IsSetGIAKHUYENMAI)
	{
    	    s += " AND GIAKHUYENMAI = @GIAKHUYENMAI ";
	}
	if (obj.IsSetNGUONGNHAP)
	{
    	    s += " AND NGUONGNHAP = @NGUONGNHAP ";
	}
	if (obj.IsSetNGUONGXUAT)
	{
    	    s += " AND NGUONGXUAT = @NGUONGXUAT ";
	}
	if (obj.IsSetISKHUYENMAI)
	{
    	    s += " AND ISKHUYENMAI = @ISKHUYENMAI ";
	}
	if (obj.IsSetISUSE)
	{
    	    s += " AND ISUSE = @ISUSE ";
	}
	if (obj.IsSetISDELETE)
	{
    	    s += " AND ISDELETE = @ISDELETE ";
	}
	if (obj.IsSetISTHEODOI)
	{
    	    s += " AND ISTHEODOI = @ISTHEODOI ";
	}
	if (obj.IsSetNGAYTAO)
	{
    	    s += " AND NGAYTAO = @NGAYTAO ";
	}
	if (obj.IsSetNGUOITAO)
	{
    	    s += " AND NGUOITAO = @NGUOITAO ";
	}
	if (obj.IsSetNGAYCAPNHAT)
	{
    	    s += " AND NGAYCAPNHAT = @NGAYCAPNHAT ";
	}
	if (obj.IsSetNGUOICAPNHAT)
	{
    	    s += " AND NGUOICAPNHAT = @NGUOICAPNHAT ";
	}
	if (obj.IsSetMALOAIMATHANG)
	{
    	    s += " AND MALOAIMATHANG = @MALOAIMATHANG ";
	}
	if (obj.IsSetGHICHU)
	{
    	    s += " AND GHICHU = @GHICHU ";
	}
            if (s.Length > 0)
            {
                s =" WHERE "+s.Substring(4);
                return s;
            }
            return "";
        }

        private void FillParamToCommand(IDbCommand command, MATHANGConditionForm obj)
        {
	    if (obj == null) { return;}
            	            if (obj.IsSetMAMATHANG)
            {
            	DalTools.addDbDataParameter(command, "MAMATHANG", obj.MAMATHANG, DbType.Int32); 
            }
            if (obj.IsSetMABARCODE)
            {
            	DalTools.addDbDataParameter(command, "MABARCODE", obj.MABARCODE, DbType.String); 
            }
            if (obj.IsSetMACODE)
            {
            	DalTools.addDbDataParameter(command, "MACODE", obj.MACODE, DbType.String); 
            }
            if (obj.IsSetTENMATHANG)
            {
            	DalTools.addDbDataParameter(command, "TENMATHANG", obj.TENMATHANG, DbType.String); 
            }
            if (obj.IsSetHINHANH)
            {
            	DalTools.addDbDataParameter(command, "HINHANH", obj.HINHANH, DbType.Binary); 
            }
            if (obj.IsSetMADONVISI)
            {
            	DalTools.addDbDataParameter(command, "MADONVISI", obj.MADONVISI, DbType.Int32); 
            }
            if (obj.IsSetMADONVILE)
            {
            	DalTools.addDbDataParameter(command, "MADONVILE", obj.MADONVILE, DbType.Int32); 
            }
            if (obj.IsSetSOLUONGQUYDOI)
            {
            	DalTools.addDbDataParameter(command, "SOLUONGQUYDOI", obj.SOLUONGQUYDOI, DbType.Int32); 
            }
            if (obj.IsSetVAT)
            {
            	DalTools.addDbDataParameter(command, "VAT", obj.VAT, DbType.Int32); 
            }
            if (obj.IsSetCHIETKHAU)
            {
            	DalTools.addDbDataParameter(command, "CHIETKHAU", obj.CHIETKHAU, DbType.Double); 
            }
            if (obj.IsSetXUATXU)
            {
            	DalTools.addDbDataParameter(command, "XUATXU", obj.XUATXU, DbType.String); 
            }
            if (obj.IsSetGIANHAP)
            {
            	DalTools.addDbDataParameter(command, "GIANHAP", obj.GIANHAP, DbType.Decimal); 
            }
            if (obj.IsSetGIALE)
            {
            	DalTools.addDbDataParameter(command, "GIALE", obj.GIALE, DbType.Decimal); 
            }
            if (obj.IsSetGIAQUYDINH)
            {
            	DalTools.addDbDataParameter(command, "GIAQUYDINH", obj.GIAQUYDINH, DbType.Decimal); 
            }
            if (obj.IsSetGIACHIATHANG)
            {
            	DalTools.addDbDataParameter(command, "GIACHIATHANG", obj.GIACHIATHANG, DbType.Decimal); 
            }
            if (obj.IsSetGIAKHUYENMAI)
            {
            	DalTools.addDbDataParameter(command, "GIAKHUYENMAI", obj.GIAKHUYENMAI, DbType.Decimal); 
            }
            if (obj.IsSetNGUONGNHAP)
            {
            	DalTools.addDbDataParameter(command, "NGUONGNHAP", obj.NGUONGNHAP, DbType.Decimal); 
            }
            if (obj.IsSetNGUONGXUAT)
            {
            	DalTools.addDbDataParameter(command, "NGUONGXUAT", obj.NGUONGXUAT, DbType.Decimal); 
            }
            if (obj.IsSetISKHUYENMAI)
            {
            	DalTools.addDbDataParameter(command, "ISKHUYENMAI", obj.ISKHUYENMAI, DbType.Boolean); 
            }
            if (obj.IsSetISUSE)
            {
            	DalTools.addDbDataParameter(command, "ISUSE", obj.ISUSE, DbType.Boolean); 
            }
            if (obj.IsSetISDELETE)
            {
            	DalTools.addDbDataParameter(command, "ISDELETE", obj.ISDELETE, DbType.Boolean); 
            }
            if (obj.IsSetISTHEODOI)
            {
            	DalTools.addDbDataParameter(command, "ISTHEODOI", obj.ISTHEODOI, DbType.Boolean); 
            }
            if (obj.IsSetNGAYTAO)
            {
            	DalTools.addDbDataParameter(command, "NGAYTAO", obj.NGAYTAO, DbType.DateTime); 
            }
            if (obj.IsSetNGUOITAO)
            {
            	DalTools.addDbDataParameter(command, "NGUOITAO", obj.NGUOITAO, DbType.String); 
            }
            if (obj.IsSetNGAYCAPNHAT)
            {
            	DalTools.addDbDataParameter(command, "NGAYCAPNHAT", obj.NGAYCAPNHAT, DbType.DateTime); 
            }
            if (obj.IsSetNGUOICAPNHAT)
            {
            	DalTools.addDbDataParameter(command, "NGUOICAPNHAT", obj.NGUOICAPNHAT, DbType.String); 
            }
            if (obj.IsSetMALOAIMATHANG)
            {
            	DalTools.addDbDataParameter(command, "MALOAIMATHANG", obj.MALOAIMATHANG, DbType.Int32); 
            }
            if (obj.IsSetGHICHU)
            {
            	DalTools.addDbDataParameter(command, "GHICHU", obj.GHICHU, DbType.String); 
            }
        }
        #endregion
    }
}